package Link;

public class leet_2 {
    public static void main(String[] args) {
        System.out.println(15%10);
    }
}

class Solution_2 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode result = new ListNode(-1);
        ListNode curr = result;

        // 进位符
        boolean operator = false;
        // 2个链表均不为空
        while(l1!=null || l2!=null){
            curr.next = new ListNode(-1);
            curr = curr.next;

            int linkInt1 = -1;
            int linkInt2 = -1;
            int bothInt = -1;

            // 判断l1与l2
            if(l1!=null){
                linkInt1 = l1.val;
                l1 = l1.next;
            }
            if(l2!=null){
                linkInt2 = l2.val;
                l2 = l2.next;
            }

            if(linkInt1<0){
                if(operator){
                    bothInt = linkInt2 + 1;
                }else {
                    bothInt = linkInt2;
                }
            }else if(linkInt2<0){
                if(operator){
                    bothInt = linkInt1 + 1;

                }else {
                    bothInt = linkInt1;
                }
            }else {
                if(operator) {
                    bothInt = linkInt1 + linkInt2 + 1;
                }else{
                    bothInt = linkInt1 + linkInt2;
                }
            }
            operator = false;

            // 开始计算值
            if((bothInt/10)>0){
                operator = true;
            }
            curr.val = bothInt%10;
        }
        if(operator){
            curr.next = new ListNode(1);
        }
        return result.next;
    }
}
